import unittest
import time

from selenium.webdriver.common.by import By

from common.base import get_driver
from page.contents_page import ContentsPage


class ContestTestCase(unittest.TestCase):
    def test_contents(self):
        # TODO 操作流程
        # 创建driver
        driver = get_driver()
        driver.get("http://localhost:8080/ecshop/")
        # 创建页面对象
        self.contents = ContentsPage(driver)
        self.contents.click_accessories()
        time.sleep(1)
        goods_name = self.contents.get_text((By.XPATH, "//a[@title='平衡车']"))
        self.contents.click_commodity()
        time.sleep(1)
        actual_goods_name = self.contents.get_text((By.XPATH, "//div[@class='goods_style_name']"))
        self.contents.change_count(2)
        time.sleep(1)
        self.contents.click_buy()
        time.sleep(3)
        self.contents.quit(3)

        # TODO 断言
        """
        预期 和 实际结果 的比对
        """
        # 结果比对
        self.assertEqual(goods_name, actual_goods_name, msg="查看到的商品有误")


if __name__ == '__main__':
    unittest.main(verbosity=2)